//
//  YXJCCell.m
//  Tunnel
//
//  Created by wbb on 2025/6/14.
//

#import "YXJCCell.h"
@interface YXJCCell ()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;

@property (nonatomic, strong) UILabel *typeLabel;
@property (nonatomic, strong) UILabel * ssxtLab;
@property (nonatomic, strong) UILabel * sbfxLab;
@property (nonatomic, strong) UILabel * sbzhLab;

@end
@implementation YXJCCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.backgroundColor = [UIColor clearColor];

        self.contentView.backgroundColor = [UIColor clearColor];
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgView];
    bgView.layer.shadowColor = [UIColor colorWithRed:156/255.0 green:175/255.0 blue:210/255.0 alpha:0.2].CGColor;
    bgView.layer.shadowOffset = CGSizeMake(0,4);
    bgView.layer.shadowOpacity = 1;
    bgView.layer.shadowRadius = 8;
    bgView.layer.cornerRadius = 7;
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.bottom.offset(-15);
        make.left.offset(12);
        make.right.offset(-12);
    }];
    
    
    // 创建标题标签
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:17];
    self.titleLabel.textColor = main_text_color;
    self.titleLabel.text = @"液位浮球 - YWJ-01";
    [bgView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.top.offset(12);
    }];
    
    self.typeLabel = [[UILabel alloc] init];
    self.typeLabel.font = [UIFont systemFontOfSize:14];
    self.typeLabel.numberOfLines = 0;
    self.typeLabel.text = @"在线";
    self.typeLabel.textAlignment = NSTextAlignmentCenter;
    self.typeLabel.textColor = hexColor(318C2D);
    self.typeLabel.backgroundColor = hexColor(EEFFEB);
    [bgView addSubview:self.typeLabel];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.titleLabel.mas_centerY).offset(0);
        make.right.offset(-8);
        make.width.offset(64);
        make.height.offset(22);
    }];
    
    
    UIStackView *stackView1 = [[UIStackView alloc] init];
    stackView1.spacing = 10;
    [bgView addSubview:stackView1];
    [stackView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.height.offset(20);
    }];
    
    UILabel *leftLab1 = [[UILabel alloc] init];
    leftLab1.text = @"所属系统";
    leftLab1.textColor = main_light_text_color_9;
    leftLab1.font = [UIFont systemFontOfSize:14];
    
    self.ssxtLab = [[UILabel alloc] init];
    self.ssxtLab.text = @"所属系统";
    self.ssxtLab.textColor = main_light_text_color_6;
    self.ssxtLab.font = [UIFont systemFontOfSize:14];
    
    [stackView1 addArrangedSubview:leftLab1];
    [stackView1 addArrangedSubview:self.ssxtLab];
    
    UIStackView *stackView2 = [[UIStackView alloc] init];
    stackView2.spacing = 10;
    [bgView addSubview:stackView2];
    [stackView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(stackView1.mas_bottom);
        make.height.offset(20);
    }];
    
    UILabel *leftLab2 = [[UILabel alloc] init];
    leftLab2.text = @"设备方向";
    leftLab2.textColor = main_light_text_color_9;
    leftLab2.font = [UIFont systemFontOfSize:14];
    
    self.sbfxLab = [[UILabel alloc] init];
    self.sbfxLab.text = @"所属系统";
    self.sbfxLab.textColor = main_light_text_color_6;
    self.sbfxLab.font = [UIFont systemFontOfSize:14];
    
    [stackView2 addArrangedSubview:leftLab2];
    [stackView2 addArrangedSubview:self.sbfxLab];
    
    
    UIStackView *stackView3 = [[UIStackView alloc] init];
    stackView3.spacing = 10;
    [bgView addSubview:stackView3];
    [stackView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(stackView2.mas_bottom);
        make.height.offset(20);
    }];
    
  
    
    UILabel *leftLab3 = [[UILabel alloc] init];
    leftLab3.text = @"设备桩号";
    leftLab3.textColor = main_light_text_color_9;
    leftLab3.font = [UIFont systemFontOfSize:14];
    
    self.sbzhLab = [[UILabel alloc] init];
    self.sbzhLab.text = @"所属系统";
    self.sbzhLab.textColor = main_light_text_color_6;
    self.sbzhLab.font = [UIFont systemFontOfSize:14];
    
    [stackView3 addArrangedSubview:leftLab3];
    [stackView3 addArrangedSubview:self.sbzhLab];
    
    
    UILabel *lineLab = [UILabel new];
    lineLab.backgroundColor = main_line_color;
    [bgView addSubview:lineLab];
    [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(stackView3.mas_bottom).offset(5);
        make.height.offset(1);
    }];
    
    self.detailLabel = [[UILabel alloc] init];
    self.detailLabel.font = [UIFont systemFontOfSize:14];
    self.detailLabel.textColor = main_text_color;
    self.detailLabel.text = @"查看详情";
    [bgView addSubview:self.detailLabel];
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.equalTo(lineLab.mas_bottom).offset(10);
    }];
    
    
    UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right_arrow"]];
    [bgView addSubview:arrowImg];
    [arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-8);
        make.centerY.equalTo(self.detailLabel.mas_centerY).offset(0);
        make.height.width.offset(22);
    }];
    
    
    
    
    
}

- (void)goDetail {
    if(self.goDetailBlock) {
        self.goDetailBlock();
    }
}
- (void)setCornerForIndexPath:(NSIndexPath *)indexPath totalRows:(NSInteger)totalRows dataSource:(NSArray *)dataArray {
    
    NSDictionary *dic = dataArray[indexPath.row];
    
    self.imgView.image = [UIImage imageNamed:dic[@"imgName"]];
    self.titleLabel.text = dic[@"title"];
}

- (void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    
    self.imgView.image = [UIImage imageNamed:dataDic[@"imgName"]];
    self.titleLabel.text = dataDic[@"title"];
//    self.contentLabel.text = dataDic[@"content"];
    self.detailLabel.text = dataDic[@"time"];
}
-(void)setModel:(YXJCModel *)model{
    self.titleLabel.text = [NSString stringWithFormat:@"%@-%@",model.devName,model.ID];
    self.typeLabel.text = model.onOffStatus == 1? @"在线":@"离线";
    self.typeLabel.textColor = model.onOffStatus == 1?hexColor(318C2D):hexColor(FF3245);
    self.typeLabel.backgroundColor = model.onOffStatus == 1?hexColorAlpha(318C2D,0.1):hexColorAlpha(FF3245,0.1);
    self.sbfxLab.text = model.direction;
    self.sbzhLab.text = model.pileNo;
    self.ssxtLab.text = model.sysType;
}
@end
